package net.dgg.zz.credential.generalCredential.controller;

import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.tmd.foundation.platform.annotation.AuthOpt;
import net.dgg.zz.common.constant.CredentialConstant;
import net.dgg.zz.credential.generalCredential.service.CertificateStatisticService;
import net.fblock.log.NLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author zsx
 * @Title: CertificateStatisticsController
 * @ProjectName zz-sc-zs
 * @Description: 证书总览
 * @date 2018/9/5 9:24
 */
@Controller()
@RequestMapping("/zs/certificate_statistics")
public class CertificateStatisticController extends DggBaseController {
    @Autowired
    private CertificateStatisticService statisticService;

    /*
     * @Author zsx
     * @Date 2018-09-05 09:09:25
     * @Description  证书总览初始化
     */
    @RequestMapping("/index")
    @AuthOpt(code = "CERTIFICATE_OVERVIEW")
    public String index(Model model) {
        model.addAttribute("reservation", CredentialConstant.GENERAL_CREDENTIAL_STATUS_RESERVATION);
        model.addAttribute("subordinate", CredentialConstant.GENERAL_CREDENTIAL_STATUS_SUBORDINATE);
        model.addAttribute("noUse", CredentialConstant.GENERAL_CREDENTIAL_STATUS_NO_USE);
        model.addAttribute("libraryStatus", CredentialConstant.GENERAL_CREDENTIAL_LIBRARY_STATUS_IN);
        model.addAttribute("local", CredentialConstant.LOCAL);
        model.addAttribute("nationwide", CredentialConstant.NATIONWIDE);
        model.addAttribute("subordinateOverDue", CredentialConstant.CREDENTIAL_OVER_DUE_TYPE_AFFILIATED);
        model.addAttribute("companyOverDue", CredentialConstant.CREDENTIAL_OVER_DUE_TYPE_COMPANY);
        model.addAttribute("talentOverDue", CredentialConstant.CREDENTIAL_OVER_DUE_TYPE_TALENTS);
        model.addAttribute("credentialOverDue", CredentialConstant.CREDENTIAL_OVER_DUE_TYPE_CREDENTIAL);

        return "zzsc/credential/certificateStatistics/all_certificate_statistics";
    }

    /*
     * @Author zsx
     * @Date 2018-09-05 10:09:45
     * @Description 获取证书超期预警
     * @param signOrgId 事业部id
     * @param isAll 是否有权查询所有 （0表示只能看自己事业部）
     * @return DggRestResponse
     */
    @RequestMapping("/get_expiration_warning")
    @ResponseBody
    @NLog
    public DggRestResponse getExpirationWarning(Long signOrgId, String isAll) {
        try {
            Map<String, Object> map = statisticService.findExpirationWarning(signOrgId, isAll);
            return this.getSuccessResponse(map);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return this.getFailResponse("获取超期预警失败");
        }
    }


}
